package com.google.jguery.client.query;

import java.util.Map;
import java.util.Set;

import com.google.jguery.client.common.FieldText;

public abstract class Query {

	FieldText ft;
	
	public abstract Set<FieldText> getAllTerms();
	
	public void existingTerms(Searcher searcher, Set<FieldText> termSet,
			boolean reverse) {
		boolean isContained = searcher.contains(ft);
		if (reverse) isContained = !isContained;
		if (isContained) termSet.add(ft);
	}
	
	public void existingTerms(Searcher searcher, Set<FieldText> termSet) {
		existingTerms(searcher, termSet, false);
	}
	
	public void allTerms(Set<FieldText> termSet) {
		termSet.add(ft);		
	}
	
	/** 
	 * @return Returns an estimate of how many documents this query could potentially
     *  match (for example, the estimated size of a simple term query is the
     *  document frequency of the term). It is permissible to overestimate, but
     *  not to underestimate.
	 */
	public abstract int estimateSize(Searcher searcher);
	
	public abstract Map<Integer, Integer> getDocScoreMap(Searcher searcher);
	
	public abstract Set<Integer> getDocIds(Searcher searcher);
	
	/**
	 * @return a recursively "normalized" form of this query. The normalized
     *  form removes redundancy and empty queries. For example,
     *  AND(AND(a, b), c, Or()) -> AND(a, b, c).
	 */
	public abstract Query normalize();
}
